package qianlong.practice.dao.impl;

import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.support.SqlSessionDaoSupport;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Repository;
import qianlong.practice.dao.UserDao;
import qianlong.practice.entity.User;

import java.util.List;

@Primary
@Repository
public class UserDaoImpl extends SqlSessionDaoSupport implements UserDao {

    public UserDaoImpl(SqlSessionFactory sqlSessionFactory){
        super.setSqlSessionFactory(sqlSessionFactory);
    }

    @Override
    public int insert(User user) {
        return super.getSqlSessionTemplate().insert("insert",user);
    }

    @Override
    public int update(User user) {
        return super.getSqlSessionTemplate().update("update",user);
    }

    @Override
    public int delete(Integer id) {
        return super.getSqlSessionTemplate().delete("delete",id);
    }

    @Override
    public User getOne(Integer id) {
        return super.getSqlSessionTemplate().selectOne("getOne",id);
    }

    @Override
    public List<User> getList(User user) {
        return super.getSqlSessionTemplate().selectList("getList", user);
    }

    @Override
    public int getCount(User user) {
        return super.getSqlSessionTemplate().selectOne("getCount",user);
    }

    @Override
    public List<User> getPage(User user) {
        return super.getSqlSessionTemplate().selectList("getPage",user);
    }
}

